
package stcu.control;

import stcu.*;
import stcu.forms.*;

import java.io.File;
import java.awt.event.*;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFileChooser;


public class ControlledServerStart extends ServerStart {

    private Server server;
    private File selectedFile;

    public ControlledServerStart(final Server server) {
        this.server = server;

        startButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                if (selectedFile != null) {
                    server.readAccounts(selectedFile);

                    server.start();
                    final ServerForm serverUI = new ControlledServerForm(server, server.getDefaultGroup());
                    javax.swing.SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            serverUI.setVisible(true);
                            setVisible(false);
                        }
                    });
                }
            }
        });

        fileChoose.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                JFileChooser fileChooser = new javax.swing.JFileChooser();
                fileChooser.setCurrentDirectory(new File("."));
                int returnVal = fileChooser.showOpenDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    selectedFile = fileChooser.getSelectedFile();
                    fileTxt.setText(selectedFile.getPath());
                } 
            }
        });
    }
}
